package server;

public enum Command {

	INCREMENT("[S:lotid:UID:param]",4), //
	DECREMENT("[S:lotid:UID:param]",4),
	GET_LC("[G:lotid:UID:param]",4),
	SET_LC("[S:lotid:UID:param]",4),
	SET_UID("[U:lotid:UID:param]",4),
	REQ_STATUS("[A:lotid:UID:param]",4),
	SEND_STATUS("[C:lotid:UID:lotCount:maxSize]",4),
	SET_LS("[Y:lotid:UID:param]",4),
	SET_SENSITIVITY("[Z:lotid:UID:param]",4),
	;
	
	private String command;
	private int parameters;
	
	Command(String command, int params){
		this.setCommand(command);		
	}

	public String sendCmd(LocalNode ln, String param){
		String cmdString = this.getCommand();
		char lotid = ln.getLotID();
		if (!this.equals(SET_UID)){
			ln.incrUID();
		}
		int uid = ln.getUID();
		cmdString = cmdString.replaceAll("lotid", Character.toString(lotid)); 
		cmdString = cmdString.replaceAll("UID", Integer.toString(uid));
		if (this.getCommand() != Command.INCREMENT.getCommand() || this.getCommand() != Command.DECREMENT.getCommand())
			cmdString = cmdString.replaceAll("param", param);
		switch (this){
			case INCREMENT:
				ln.incrLotCount();
				cmdString = cmdString.replaceAll("param", String.valueOf((ln.getLotCount())));
				break;
			case DECREMENT:
				ln.decrLotCout();
				cmdString = cmdString.replaceAll("param", String.valueOf((ln.getLotCount())));
				break;
			case SET_LC:
				ln.setLotCount(Integer.valueOf(param));
				cmdString = cmdString.replaceAll("param", String.valueOf((ln.getLotCount())));
				break;
			case SET_UID:
				ln.setUID(Integer.valueOf(param));
				break;
			case SET_LS:
				ln.setLotSize(Integer.valueOf(param));
				break;
			case SET_SENSITIVITY:
				ln.setSensitivity(Integer.valueOf(param));
				break;
			case REQ_STATUS:
				break;
			case SEND_STATUS:
				cmdString = cmdString.replaceAll("lotCount", String.valueOf((ln.getLotCount())));
				cmdString = cmdString.replaceAll("maxSize", String.valueOf((ln.getLotSize())));
				break;
		}
		return cmdString;
	}
	
	public String getCommand() {
		return command;
	}

	public void setCommand(String command) {
		this.command = command;
	}

	public int getParameters() {
		return parameters;
	}

	public void setParameters(int parameters) {
		this.parameters = parameters;
	}
	
}
